/*
 Copyright 2012 Ronald Pablos 

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package org.bn.types;

import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Ronald
 */
public class TimeOfDay {
    static Pattern p = Pattern.compile("(\\d{2}):?(\\d{2}):?(\\d{2})");
    int hour, min, seg;
    
    public TimeOfDay(int hour, int min, int seg) {
        this.hour = hour;
        this.min = min;
        this.seg = seg;
    }
    public TimeOfDay(String theTime) {
       
        Matcher m = p.matcher(theTime);
        if (!m.matches())
            throw new IllegalArgumentException("Time string is not the format HH:mm:ss");
        
        hour = Integer.parseInt(m.group(1));
        min = Integer.parseInt(m.group(2));
        seg = Integer.parseInt(m.group(3));
    }

    public int getHour() {
        return hour;
    }

    public int getMin() {
        return min;
    }

    public int getSeg() {
        return seg;
    }

    public void setHour(int hour) {
        this.hour = hour;
    }

    public void setMin(int min) {
        this.min = min;
    }

    public void setSeg(int seg) {
        this.seg = seg;
    }

    @Override
    public String toString() {
        return String.format("%1$02d:%2$02d:%3$02d",hour,min,seg);
        
    }
    
}
